import request from '../utils/request';
import config from '../common/config';
import { getCookie } from '../utils/utils';

const getOptions = function() {
  const adminToken = getCookie('adminToken');
  const htk = adminToken ? { adminToken } : {};
  const options = {};
  const token = localStorage.getItem('admintoken');
  options.headers = {
    ...htk,
  };
  if (token) {
    options.headers.Authorization = `Bearer ${token}`;
    options.method = 'POST';
  }

  return options;
};

export async function query() {
  return request('/api/users');
}

export async function queryCurrent(params) {
  const options = getOptions();

  options.body = params;
  return request(`${config.serveraddress}/api/user/profile/query`, options);
}
